package cn.itcast.user.web;

import cn.itcast.user.pojo.User;
import cn.itcast.user.properties.PropertiesConfiguration;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RefreshScope //热更新注解 实时刷新nacos配置中心的配置
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Value("username")
    private String username;

    @Autowired
    private PropertiesConfiguration propertiesConfiguration;
//    @Value("${pattern.dateformat}")
//    private String dateformat;

    @RequestMapping("/header")
    public String getheader(@RequestHeader String Truth){

        return Truth;
    }
    @GetMapping("/now")
    public String getDateformat(){
        System.out.println("用户名:"+username);
        LocalDateTime now = LocalDateTime.now();
        String format = now.format(DateTimeFormatter.ofPattern(propertiesConfiguration.getDateformat()));
        return format;
    }
    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {
        return userService.queryById(id);
    }
}
